package com.hjm.admin.moule.viewmodel.activity;

import android.content.Context;

import com.allen.library.RxHttpUtils;
import com.allen.library.interceptor.Transformer;
import com.allen.library.utils.ToastUtils;
import com.hjm.admin.moule.MyApp;
import com.hjm.admin.moule.api.UserService;
import com.hjm.admin.moule.model.AppUpdateBean;
import com.hjm.admin.moule.utils.rxhelper.RxObserver;
import com.hjm.admin.moule.view.activity.ISetting;
import com.hjm.admin.moule.viewmodel.BaseViewModel;


public class VMSettingInfo extends BaseViewModel {
    ISetting mISetting;

    public VMSettingInfo(Context mContext, ISetting iSetting) {
        super(mContext);
        mISetting = iSetting;
    }

    public  void appUpdate(boolean isTip) {
        mISetting.showLoading();
        RxHttpUtils.getInstance().createApi(UserService.class)
        .appUpdate()
        .compose(Transformer.switchSchedulers())
        .subscribe(new RxObserver<AppUpdateBean>() {
            @Override
            protected void onError(String errorMsg) {

            }

            @Override
            protected void onSuccess(AppUpdateBean data) {
                mISetting.stopLoading();
                if(MyApp.packageInfo.versionCode<data.getVersioncode()){
                    mISetting.appUpdate(data);
                }else {
                    if(isTip){
                        ToastUtils.showToast("当前已是最新版本");
                    }
                }
            }
        });
    }
}
